package org.springframework.ioc.beanfactory.beanprocess;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Constructor;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor;

public class CustomSmartInstantiationAwareBeanPostProcessor implements SmartInstantiationAwareBeanPostProcessor {

	@Override
	public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
		System.out.println(getClass().getName()+" postProcessBeforeInstantiation method is running");
		try {
			return beanClass.newInstance();
		} catch (Exception e) {
			throw new BeanCreationException(" bean class instance fails");
		} 
	}

	@Override
	public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
		System.out.println(getClass().getName()+" postProcessAfterInstantiation method is running");
		return false;
	}

	@Override
	public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean,
			String beanName) throws BeansException {
		System.out.println(getClass().getName()+" postProcessPropertyValues method is running");
		return pvs;
	}

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		System.out.println(getClass().getName()+" postProcessBeforeInitialization method is running");
		return bean;
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		System.out.println(getClass().getName()+" postProcessAfterInitialization method is running");
		return bean;
	}

	@Override
	public Class<?> predictBeanType(Class<?> beanClass, String beanName) throws BeansException {
		System.out.println(getClass().getName()+" predictBeanType method is running");
		return beanClass;
	}

	@Override
	public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName) throws BeansException {
		System.out.println(getClass().getName()+" determineCandidateConstructors method is running");
		return beanClass.getConstructors();
	}

	@Override
	public Object getEarlyBeanReference(Object bean, String beanName) throws BeansException {
		System.out.println(getClass().getName()+" getEarlyBeanReference method is running");
		return bean;
	}

}
